package lighthouse_cmd

import (
	"context"
	"fmt"
	"time"

	my_common "atomgit.com/openlinksaas-org/tencloud/common"
	"github.com/spf13/cobra"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
	lighthouse_client "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse/v20200324"
)

var listInstanceCmdInstanceIdList = []string{}

var _listInstanceCmd = &cobra.Command{
	Use: "listInstance",
	Run: func(cmd *cobra.Command, args []string) {
		client, err := lighthouse_client.NewClient(common.NewCredential(my_common.CmdSecretId, my_common.CmdSecretKey), my_common.CmdRegion, profile.NewClientProfile())
		if err != nil {
			my_common.OutputError(err)
		}
		ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
		defer cancel()
		req := lighthouse_client.NewDescribeInstancesRequest()
		limit := int64(100)
		req.Limit = &limit
		if len(listInstanceCmdInstanceIdList) > 0 {
			tmpIdList := []*string{}
			for _, instanceId := range listInstanceCmdInstanceIdList {
				tmpIdList = append(tmpIdList, &instanceId)
			}
			req.InstanceIds = tmpIdList
		}
		res, err := client.DescribeInstancesWithContext(ctx, req)
		if err != nil {
			my_common.OutputError(err)
		}
		fmt.Println(res.ToJsonString())
	},
}

func init() {
	_listInstanceCmd.Flags().StringArrayVar(&listInstanceCmdInstanceIdList, "instance", []string{}, "filter by instance")
}
